---
title: Distribute a document (synchronous or asynchronous)
summary: Delivers a document via a direct SOAP call or via an MSMQ queue for asynchronous distribution.
status: draft
owner: SAIF Case Management
last_reviewed: 2026-08-21
library: SAIF.Services.Printing
reference_type: embedded
operation_id: OP-PRINT-DISTRIBUTE
trigger: Caller invokes clsPrint.distributeDocument
---

# Distribute a document (synchronous or asynchronous)

Delivers an xPression document either immediately via a synchronous SOAP call, or deferred via an MSMQ queue for asynchronous processing.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-PRINT-DISTRIBUTE |
| **Trigger** | Caller invokes the public `distributeDocument(package, xml)` overload, or sets properties directly and invokes the private `distributeDocument()` |
| **Inputs** | `Package`, `XML` (trimmed), `Asynchronous` flag, printer/plex/scale/copies, `OutputProfile`, `ImportInfo`, email/fax info, `IDMPath`, deferred-print info |
| **Outputs** | Boolean success flag (`True` after successful completion) |
| **Primary components** | `clsPrint.distributeDocument`, `clsPrint.StartMQTransaction`, `clsPrint.EndMQTransaction` |
| **Entry point** | `SAIF.Services.Printing\clsPrint.vb` |

## Steps

1. Caller sets `Package`/`XML` (trimmed) via the public overload, or directly via properties, then invokes the private `distributeDocument()`.
2. If `Asynchronous = True`:
   - Lazily opens/reuses an MSMQ `MessageQueue` at `m_MessagePath` (the [`documentMSMQPath`](../configuration.md) configuration setting).
   - Builds a `CompositeRequestClass` snapshot of all current property values (package, XML, printer, plex/scale mode, copies, format, output profile, import info, email info, fax info, IDM path, deferred info).
   - Serializes the request with `Messaging.BinaryMessageFormatter` into a `Message`.
   - Ensures an MSMQ transaction is active — calls [MSMQ transaction lifecycle: `StartMQTransaction()`](msmq-transaction-lifecycle.md) if one was not already started by the caller, sends the message, then commits the transaction ([`EndMQTransaction(True)`](msmq-transaction-lifecycle.md)) if it started the transaction itself.
     - On any exception: rolls back the transaction ([`EndMQTransaction(False)`](msmq-transaction-lifecycle.md)) and re-throws.
3. If `Asynchronous = False`: calls `m_Xpresso.distributeDocument(...)` directly (synchronous SOAP call) with the same full parameter set, hard-coding `PaperTray.Tray2` as the tray selection.
   > **Origin**: This step is implemented in `xpresso.clsGenerate` (`SAIF.Services.Printing.xpresso`) and executed against the external xPression Design server.*
4. Returns `True` (public overload) after the private method completes without throwing.

## Process flow

```mermaid
flowchart TD
	Start([Caller sets Package/XML]) --> Decision{Asynchronous?}
	Decision -->|Yes| Queue[Build CompositeRequestClass]
	Queue --> Serialize[Serialize with BinaryMessageFormatter]
	Serialize --> Txn[Start/reuse MSMQ transaction]
	Txn --> Send[Send message to MSMQ queue]
	Send --> Commit[Commit transaction]
	Commit --> EndOk([Return True])
	Send -->|Exception| Rollback[Rollback transaction and re-throw]
	Decision -->|No| Sync[Call m_Xpresso.distributeDocument]
	Sync --> EndOk
```

## Failure and edge-case behavior
- On any exception during the asynchronous path, the MSMQ transaction is rolled back (`EndMQTransaction(False)`) and the exception is re-thrown to the caller.
- The synchronous path hard-codes `PaperTray.Tray2`; no caller-supplied tray override is honored for synchronous distribution.*

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `SAIF.Services.Printing\clsPrint.vb`
- `SAIF.Services.Printing\Web References\xpresso\Reference.vb`
